package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysMenuService;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.entity.sys.SysMenu;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * title:
 * author: zgl
 * date: 2023/12/30
 * description：
 */
@RestController
@RequestMapping("/admin/system/menu")
@Tag(name = "菜单管理模块")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;

    //查询所有菜单
    @GetMapping("/menuList")
    @Operation(summary = "获取级联菜单接口")
    public Result getMenuList() {
        List<SysMenu> menuList = sysMenuService.getMenuList();
        return Result.ok(menuList);
    }

    //添加菜单
    @PostMapping("/saveFatherMenu")
    @Operation(summary = "添加菜单接口")
    public Result saveFatherMenu(@RequestBody SysMenu sysMenu) {
        sysMenuService.saveFatherMenu(sysMenu);
        return Result.ok();
    }

    //删除菜单
    @DeleteMapping("/deleteMenu/{id}")
    @Operation(summary = "删除菜单接口")
    public Result deleteMenu(@PathVariable Long id) {
        sysMenuService.deleteMenu(id);
        return Result.ok();
    }

    //添加下级节点
    /*@PostMapping("/saveSonMenu")
    public Result saveSonMenu(@RequestBody SysMenu sysMenu){
        sysMenuService.saveSonMenu(sysMenu);
        return Result.ok();
    }*/

    //修改菜单
    @PutMapping("/updateMenu")
    @Operation(summary = "修改菜单接口")
    public Result updateMenu(@RequestBody SysMenu sysMenu) {
        sysMenuService.updateMenu(sysMenu);
        return Result.ok();
    }

    //根据id获取菜单
    @GetMapping("/getMenus")
    @Operation(summary = "id获取菜单接口")
    public Result getMenus() {
        List<SysMenu> menuList = sysMenuService.getMenus();
        return Result.ok(menuList);
    }
}
